package com.liuyandog.DBserver;

import java.sql.*;
import java.util.ArrayList;

public class DBserver {
    String dbURL="jdbc:mysql://localhost:3306/information_schema";
    String dbDriver="com.mysql.cj.jdbc.Driver";
    String dbUserName="root";
    String dpPassword="123456";
    String sqlString="Select *\n" +
                     "From library.book\n" +
                        "where Bname='LQ单手狙击'";
    String operationClass;
    Connection ct = null;
    ResultSet rs = null;

    public DBserver(String sqlString) throws ClassNotFoundException, SQLException {
        this.sqlString = sqlString;
        Class.forName(dbDriver);
        ct= DriverManager.getConnection(dbURL,dbUserName,dpPassword);
    }

    PreparedStatement ps = null;
    public DBserver() throws ClassNotFoundException, SQLException {
        Class.forName(dbDriver);
        ct= DriverManager.getConnection(dbURL,dbUserName,dpPassword);
    }

    public void setSqlString(String sqlString) {
        this.sqlString = sqlString;
    }

    public ArrayList<String> select() throws SQLException {
        ps=ct.prepareStatement(sqlString);
        ArrayList<String> arrayList=new ArrayList<String>();
        rs=ps.executeQuery();
        while(rs.next()){
            try {
                for (int i = 1; i <= 12; i++)
                   arrayList.add(rs.getString(i));
            }catch (Exception e){

            }
        }
        System.out.println("sql select ok");
        return arrayList;
    }
    public  boolean update(){

        return false;
    }
    public boolean delete(){

        return false;
    }
    public boolean insert(){

        return false;
    }

    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        DBserver n=new DBserver();
        System.out.println("0k");
        n.select();
    }
}
